<template>
  <div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column fixed prop="type" label="类别"></el-table-column>
      <el-table-column prop="xAxis" label="X轴数据"></el-table-column>
      <el-table-column prop="yAxis" label="Y轴数据"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="primary" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
      <el-form  label-width="80px">
      <el-form-item label="类别">
        <el-input disabled="" v-model="form.type"></el-input>
      </el-form-item>
      <el-form-item label="X轴数据">
        <el-input type="textarea" v-model="form.xAxis"></el-input>
      </el-form-item>
      <el-form-item label="Y轴数据">
        <el-input type="textarea" v-model="form.yAxis"></el-input>
      </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitBtn">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { reqFish,reqFishEdit } from "../../api";
export default {
  data() {
    return {
      dialogVisible: false,
      form:{
        type:'',
        xAxis:'[]',
        yAxis:'[]',
        id:''
      },
      tableData: [
      ]
    };
  },
  created(){
    reqFish().then(res=>{
      res.map(item=>{
        item.xAxis = JSON.stringify(item.xAxis);
        item.yAxis = JSON.stringify(item.yAxis);
        return item;
      })
      this.tableData = res
    }).catch(err=>{
      console.log(err)
    })
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    handleClick(row){
      console.log(row)
       this.dialogVisible = true;
       this.form = row;
      /*let row2 = JSON.parse(JSON.stringify(row))
      row2.xAxis = JSON.stringify(row2.xAxis)
      row2.yAxis = JSON.stringify(row2.yAxis)
      this.form = row2;*/
    },
    submitBtn(){
      this.dialogVisible = false;
       let row2 = JSON.parse(JSON.stringify(this.form))
      row2.xAxis = JSON.parse(row2.xAxis)
      row2.yAxis = JSON.parse(row2.yAxis)
      reqFishEdit(row2).then(res=>{
        this.$message({
          message:'更新成功',
          type:'success'
        })
      }).catch(err=>{
        console.log(err);
         this.$message({
          message:'更新失败',
          type:'error'
        })
      })
    }
  }
};
</script>
<style>
</style>